namespace ObjectPersistence {
    using System;
    using System.Text;
    using System.Collections;
    using System.Data.Common;
    using System.Transactions;
    using System.Collections.Generic;
    
    public partial class ProjectSlideAssembler : AssemblerBaseUpdatable<KYO.DAL.ProjectSlide, ProjectSlideCriteria, ProjectSlideRowMap, ProjectSlideDomainObjectFactory> {
        public ProjectSlideAssembler() {
            base.connection = new System.Data.SqlClient.SqlConnection(GlobalUtil.Constants.ConnectionString);
        }
        protected override System.Data.Common.DbConnection InstanceConnection {
            get {
                return this.connection;
            }
        }
        /// <summary>Reads a single object from the database corresponding to the object keys which are passed in</summary>
        public KYO.DAL.ProjectSlide ReadSingleByKey(int ProjectSlideID) {
            ProjectSlideCriteria criteria = new ProjectSlideCriteria();
            criteria.Set_ProjectSlideID(ProjectSlideCriteria.AVAILABLE_OPERATORS.EQUALS, ProjectSlideID);
            return this.ReadSingle(criteria);
        }

        internal override void MakePersistent(KYO.DAL.ProjectSlide PersistentObject, bool cascade, System.Data.Common.DbCommand comm) {
            if ((PersistentObject.IsNew == false)) {
                if ((GlobalUtil.Constants.ObjectMapKYOPHUONGDOPC.Contains(PersistentObject.ROKeyString) 
                            && (PersistentObject.ChangesMade == false))) {
                    return;
                }
                if ((GlobalUtil.Constants.ObjectMapKYOPHUONGDOPC.Contains(PersistentObject.ROKeyString) == false)) {
                    GlobalUtil.Constants.ObjectMapKYOPHUONGDOPC.Add(PersistentObject.ROKeyString);
                }
            }

            if ((PersistentObject.IsNew || PersistentObject.ChangesMade)) {
                ProjectSlideUpdateFactory updateFactory = new ProjectSlideUpdateFactory();
                comm.Parameters.Clear();
                if ((PersistentObject.IsNew == false)) {
                    updateFactory.updateCommandText(PersistentObject, comm);
                    int numRows = comm.ExecuteNonQuery();
                    if ((numRows == 0)) {
                        throw new NoRowsUpdated();
                    }
                }
                else {
                    updateFactory.insertCommandText(PersistentObject, comm);
                    comm.CommandText = (comm.CommandText + "; SELECT SCOPE_IDENTITY();");
                    decimal NewIdentityKey = ((decimal)(comm.ExecuteScalar()));
                    PersistentObject.ProjectSlideID = ((int)(NewIdentityKey));
                    GlobalUtil.Constants.ObjectMapKYOPHUONGDOPC.Add(PersistentObject.ROKeyString);
                    PersistentObject.IsNew = false;
                }
            }
            PersistentObject.ChangesMade = false;

        }

        internal override void Delete(KYO.DAL.ProjectSlide PersistentObject, System.Data.Common.DbCommand comm) {
            comm.Parameters.Clear();

            ProjectSlideSelectionFactory tempProjectSlideSelectionFactory = new ProjectSlideSelectionFactory();
            string sql = "DELETE FROM [dbo].[ProjectSlide]";
            comm.CommandText = sql;
            tempProjectSlideSelectionFactory.getDefaultSelection(PersistentObject, comm);
            comm.ExecuteNonQuery();
        }

        #region Helper Utilities
        protected override ProjectSlideRowMap fillRowMap(System.Data.Common.DbDataReader reader) {
            ProjectSlideRowMap result = new ProjectSlideRowMap();
            result.ProjectSlideID = reader.GetInt32(reader.GetOrdinal("dboProjectSlideDOTProjectSlideID"));
            result.LinkUrl = reader.GetString(reader.GetOrdinal("dboProjectSlideDOTLinkUrl"));
            result.LinkImage = reader.GetString(reader.GetOrdinal("dboProjectSlideDOTLinkImage"));
            result.Odering = reader.GetInt32(reader.GetOrdinal("dboProjectSlideDOTOdering"));
            result.Published = reader.GetBoolean(reader.GetOrdinal("dboProjectSlideDOTPublished"));
            if ((reader.IsDBNull(reader.GetOrdinal("dboProjectSlideDOTTitle")) == false)) {
                result.Title = reader.GetString(reader.GetOrdinal("dboProjectSlideDOTTitle"));
            }
            if ((reader.IsDBNull(reader.GetOrdinal("dboProjectSlideDOTDescription")) == false)) {
                result.Description = reader.GetString(reader.GetOrdinal("dboProjectSlideDOTDescription"));
            }
            return result;
        }
        internal override void ClearList() {
            GlobalUtil.Constants.ObjectMapKYOPHUONGDOPC.Clear();
        }

        public override string Abstract_SELECT {
            get {
                return ("SELECT " + ProjectSlideAssembler.RawFields);
            }
        }
        protected override string InstanceTable {
            get {
                return "[dbo].[ProjectSlide]";
            }
        }
        public const string RawFields = @"[dbo].[ProjectSlide].[ProjectSlideID] AS dboProjectSlideDOTProjectSlideID, [dbo].[ProjectSlide].[Description] AS dboProjectSlideDOTDescription, [dbo].[ProjectSlide].[LinkImage] AS dboProjectSlideDOTLinkImage, [dbo].[ProjectSlide].[LinkUrl] AS dboProjectSlideDOTLinkUrl, [dbo].[ProjectSlide].[Odering] AS dboProjectSlideDOTOdering, [dbo].[ProjectSlide].[Published] AS dboProjectSlideDOTPublished, [dbo].[ProjectSlide].[Title] AS dboProjectSlideDOTTitle";
        public const string SELECT = @"SELECT [dbo].[ProjectSlide].[ProjectSlideID] AS dboProjectSlideDOTProjectSlideID, [dbo].[ProjectSlide].[Description] AS dboProjectSlideDOTDescription, [dbo].[ProjectSlide].[LinkImage] AS dboProjectSlideDOTLinkImage, [dbo].[ProjectSlide].[LinkUrl] AS dboProjectSlideDOTLinkUrl, [dbo].[ProjectSlide].[Odering] AS dboProjectSlideDOTOdering, [dbo].[ProjectSlide].[Published] AS dboProjectSlideDOTPublished, [dbo].[ProjectSlide].[Title] AS dboProjectSlideDOTTitle";
        #endregion
    }
}
